import datetime
import time

import setproctitle
import subprocess
import sys
from tools.celery_worker import load_celery

# 设置自定义进程名称

app = load_celery()
# if __name__ == '__main__':
#     # 使用 subprocess 调用 flower 命令
#     setproctitle.setproctitle('我的经常')
#     setproctitle.setthreadtitle('我的线程')
#     process = subprocess.run(
#         [
#             "celery",
#             "-A",
#             "flower_service",
#             "worker", # 替换为你的 Celery 应用名称
#         ],
#         check=True
#     )
#     print(process)
def singleton(cls):
    instances = {}
    def get_instance(*args, **kwargs):
        if cls not in instances:
            instances[cls] = cls(*args, **kwargs)
        return instances[cls]
    return get_instance

@singleton
class AlgoRunDemo:
    def __init__(self):
        # 初始化操作
        pass

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        # 清理操作
        print("AlgoRunDemo object is being destroyed")


def tast_demo(config):
    #获取一个全局对象，初次加载
    print("第一次加载,初始化算法对象")
    algo = AlgoRunDemo()

    #不运行的时候，销毁对象模型
    # 使用 with 语句
    with algo as algo:
        # 使用 algo 对象
        print("Using AlgoRunDemo object")


if __name__ == '__main__':
    print("test")
    # 时间戳（毫秒）
    timestamp_ms = 1734327009908

    # 将毫秒转换为秒
    timestamp_s = timestamp_ms / 1000.0
    # 时间戳（毫秒）
    timestamp_ms = 1734327009908

    # 将毫秒转换为秒
    timestamp_s = timestamp_ms / 1000.0

    # 转换为 datetime 对象
    dt_object = datetime.datetime.fromtimestamp(timestamp_s)

    # 打印可读时间格式
    print("可读时间格式:", dt_object)
    # 转换为 datetime 对象
    dt_object = datetime.datetime.fromtimestamp(timestamp_s)

    # 打印可读时间格式
    print("可读时间格式:", dt_object)

    print("hello world",time.time())

